import standsData from "./edit_data"
import listData from "./list_data";
import booth_data from "./booth_data";
import {isEmpty} from "../../../js/commonUtils";

let categoryList = [];

let returnFilters = [];

const standsTypes = [
  {value: 100, label: '首页展厅'},
  {value: 200, label: '分类展厅'},
  {value: 300, label: '普通展厅'},
  {value: 400, label: 'html页面'}
];
const standsPlatforms = [
  {value: 1, label: "PC (含Mobile) Only"},
  {value: 2, label: "APP Only"},
  {value: 3, label: "PC and APP"},
];

let standsTags = [
  // {value: "首页", label: "首页"},
  // {value: "分类", label: "分类"},
  // {value: "普通", label: "普通"},
  // {value: "固定", label: "固定"},
  // {value: "临时", label: "临时"},
];

const standsStates = [
  {value: 0, label: "已下线"},
  {value: 1, label: "已上线"},
];

const pageStates = [
  {value: 0, label: "新建"},
  {value: 1, label: "已预览"},
  {value: 2, label: "已发布"},
  {value: 3, label: "已修改"},
];

const standsDic = {
  types: standsTypes,
  platforms: standsPlatforms,
  tags: standsTags,
  states: standsStates,
  pageStates: pageStates,
  unPublishedState: 0,
  publishedState: 1,
  previewedPublishState: 1,
  modifiedPublishState: 3,
  indexPageType: 100,
  categoryType: 200,
  commonType: 300,
  htmlType: 400,
  pcPlatform: 1,
  appPlatform: 2,
  unionPlatform: 3,
  folderType: 6,
}

const pathPrefix = "https://d1ww9fdmfwkmlf.cloudfront.net/booth_sample/booth_";

const boothTypes = [
  {value: 1, label: "Banner", desc: "Banner轮播", img: pathPrefix+"1.jpg",},
  {value: 2, label: "单行单图", desc: "仅有一个展位", img: pathPrefix+"2.jpg",},
  // {value: 3, label: "产品列表"},
  {value: 4, label: "多行平铺", desc: "按次序平铺展开", img: pathPrefix+"4.gif",},
  {value: 5, label: "左一右二", desc: "左右平分，左一右二", img: pathPrefix+"5.jpg",},
  {value: 6, label: "左二右一", desc: "左右平分，左二右一", img: pathPrefix+"6.jpg",},
  {value: 7, label: "分类列表", desc: "展示分类入口", img: pathPrefix+"7.jpeg",},
  {value: 8, label: "导航栏", desc: "文字版超链接列表", img: pathPrefix+"8.jpg",},
  {value: 9, label: "多图左右滑动", desc: "多图左右滑动(1行或2行)", img: pathPrefix+"9.jpg",},
  {value: 10, label: "富文本", desc: "富文本网页片段", img: pathPrefix+"10.jpg",},
];

const boothStates = [
  {value: 0, label: "未上架"},
  {value: 1, label: "已上架"},
];

const boothDic = {
  types: boothTypes,
  platforms: standsPlatforms,
  bannerType: 1,
  singleType: 2,
  // productListType: 3,
  tiledType: 4,
  left1Right2Type: 5,
  left2Right1Type: 6,
  categoryListType: 7,
  navigateType: 8,
  slideType: 9,
  htmlType: 10,
  typeImgKeyPrefix: pathPrefix,
  states: boothStates,
  offlineState: 0,
  onlineState: 1,
};

const boothItemTypes = [
  {value: 1, label: "产品集合"},
  {value: 2, label: "html页面"},
  {value: 3, label: "展厅"},
  {value: 4, label: "无跳转目标"},
  {value: 5, label: "html展厅"},
  {value: 6, label: "富文本"},
];

const boothItemDic = {
  types: boothItemTypes,
  collectionType: 1,
  htmlType: 2,
  showroomType: 3,
  htmlShowroomType: 5,
};

const collectionTypes = [
  {value: 1, label: "手动添加产品"},
  {value: 2, label: "分类+关键词+时间"},
  {value: 3, label: "分类"},
  // {value: 4, label: "上架日期"}
];

const filterList = [
  {value: "Gender", label: "Gender"},
  {value: "Material", label: "Material"},
  {value: "Size", label: "Size"},
  {value: "Price", label: "Price"},
]

const collectionDic = {
  types: collectionTypes,
  customType: 1,
  keywordType: 2,
  categoryType: 3,
  dateRangeType: 4,
  filterList: filterList,
};

const getStands = () => {
  if(standsData.tStatus.stands.modalModify.isShow) {
    return standsData.tParam.editParam.stands;
  }
  if(listData.tStatus.modalAdd.isShow) {
    return listData.tParam.addParam;
  }
  return null;
}

//校验展厅关联分类
const checkStandsCategory = (rule, value, callback) => {
  let stands = getStands();
  if(stands.type == standsDic.categoryType) {
    if(isEmpty(stands.classificationId) || isEmpty(stands.classificationLevel)) {
      callback(new Error("关联分类不能为空！"));
      return;
    }
  }
  callback();
}

//校验展厅固定网址
const checkStandsShortLink = (rule, value, callback) => {
  let stands = getStands();
  if(stands.type == standsDic.commonType) {
    if(isEmpty(stands.shortLinkName)) {
      callback(new Error("请填写展厅固定网址！"));
      return;
    }
  }
  callback();
}

const isShortLinkRequired = () => {
  let stands = getStands();
  return stands&&stands.type == standsDic.commonType;
}

//产品集合标题是否必填
const isStandsCollectionTitleRequired = () => {
  let stands = getStands();
  return stands&&stands.hasProductArea;
}

//产品集合搜索关键词是否必填
const isStandsCollectionKeywordRequired = () => {
  let stands = getStands();
  return stands&&stands.hasProductArea&&stands.collectionType==collectionDic.keywordType;
}

//校验产品集合标题
const checkStandsCollectionTitle = (rule, value, callback) => {
  let stands = getStands();
  if(stands.hasProductArea) {
    if(isEmpty(stands.collectionTitle)) {
      callback(new Error("请填写产品集合标题！"));
      return;
    }
  }
  callback();
}
//校验产品集合类型
const checkStandsCollectionType = (rule, value, callback) => {
  let stands = getStands();
  if(stands.hasProductArea) {
    if(stands.collectionType == "" || stands.collectionType == null) {
      callback(new Error("请选择产品集合类型！"));
      return;
    }
  }
  callback();
}
//校验产品集合搜索关键词
const checkStandsCollectionKeyword = (rule, value, callback) => {
  let stands = getStands();
  if(stands.hasProductArea) {
    if(stands.collectionType == collectionDic.keywordType) {
      if(isEmpty(value)) {
        callback(new Error("请输入搜索关键词！"));
        return;
      }
    }
  }
  callback();
}

const getBoothItemTargetType = () => {
  let targetType = booth_data.tParam.addParam.boothItem.targetType;
  if(booth_data.tStatus.boothItem.modalModify.isShow) {
    targetType = booth_data.tParam.editParam.boothItem.targetType;
  }
  return targetType;
}

const isBoothItemValueRequired = () => {
  let targetType = getBoothItemTargetType();
  return targetType == boothItemDic.htmlType;
}

/**校验展位targetValue字段*/
const checkBoothItemValue = (rule, value, callback) => {
  let targetType = getBoothItemTargetType();
  if(targetType == boothItemDic.htmlType) {
    if(isEmpty(value)) {
      callback(new Error("请填写html页面链接地址！"));
      return;
    }
  }
  callback();
};

const rules = {
  standsRules: {
    // title: [
    //   { required: true, message: '请填写标题！', trigger: 'change'},
    // ],
    platform:[
      { required: true, type: "integer", message: '请选择展示平台！', trigger: 'change'},
    ],
    type:[
      { required: true, type: "integer", message: '请选择展厅类型！', trigger: 'change'},
    ],
    /*hasProductArea: [
      { required: true, type: "boolean", message: '请设置展厅是否有产品区！', trigger: 'change'},
    ],*/
    shortLinkName:[
      { validator: checkStandsShortLink, trigger: 'change'},
    ],
    // classificationId: [
    //   { validator: checkStandsCategory, trigger: 'change' },
    // ],
    collectionTitle: [
      { validator: checkStandsCollectionTitle, trigger: 'change'},
    ],
    collectionType: [
      { validator: checkStandsCollectionType, trigger: 'change'},
    ],
    collectionKeyword: [
      { validator: checkStandsCollectionKeyword, trigger: 'change'},
    ],
  },
  boothRules: {
    title: [
      { required: true, message: '请填写标题！', trigger: 'change'},
    ],
    displayType: [
      { required: true, type: "integer", message: '请选择展示类型！', trigger: 'change'},
    ],
    width: [
      { required: true, type: "integer", message: '请填写展区宽度！', trigger: 'change'},
    ],
    height: [
      { required: true, type: "integer", message: '请填写展区高度！', trigger: 'change'},
    ],
  },
  boothItemRules: {
    title: [
      { required: true, message: '请填写标题！', trigger: 'change'},
    ],
    targetType: [
      { required: true, type: "integer", message: '请选择展位类型！', trigger: 'change'},
    ],
    targetValue: [
      { validator: checkBoothItemValue, trigger: 'change'},
    ],
  },
  productRules: {
    sequence: [
      { required: true, message: '请填写序号！', trigger: 'change'},
    ],
  },
};

export default {
  categoryList: categoryList,
  returnFilters: returnFilters,
  standsDic: standsDic,
  boothDic: boothDic,
  boothItemDic: boothItemDic,
  collectionDic: collectionDic,
  rules: rules,
}
